package com.qf.service;

import com.qf.constant.CacheConstants;
import com.qf.feign.CacheFeign;
import com.qf.model.StandardSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 实现黑名单过滤策略
 *
 *     "phase,black,limitFiveMinutes,dirtyWords,fee,router".split(,)
 * @author lixu
 */
@Service("black")
@Slf4j
public class BlackFilterServiceImpl implements FilterChainService {

    @Autowired
    private CacheFeign cacheFeign;

    /**
     * 实现黑名单过滤策略
     * **黑名单过滤 : **平台实现系统级的手机号黑名单控制，限制某些号码的消息的发送，对发送短信进行过滤.
     *
     * - 如果是黑名单就把发送日志存到Elasticsearch
     * - 如果同时是HTTP的发送方式就模拟出状态报告推送给客户
     * @param standardSubmit
     * @return
     */
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        System.out.println("======实现黑名单过滤策略====");

        String blackKey = CacheConstants.CACHE_PREFIX_BLACK + standardSubmit.getDestMobile();
        String value = this.cacheFeign.get(blackKey);
        if(!StringUtils.isEmpty(value) && "1".equals(value)){//黑名单中的手机  没有改邪归正
            log.error("策略模块-[黑名单策略]:有此" + standardSubmit.getDestMobile());
            return false;
        }
        //不在黑名单中
        return true;
    }


}
